#include "src/avl_tree/avl_tree.cpp"


void TestAvlTree(){

    AVLNode* root = nullptr;

    printf("\ntest insert node: \n");
    root = InsertNode(root,10);
    root = InsertNode(root,20);
    root = InsertNode(root,30);
    root = InsertNode(root,40);
    root = InsertNode(root,50);
    root = InsertNode(root,25);

    printf("preordertraverse: ");
    PreOrderTraverse(root);
    printf("\n");

    printf("midordertraverse: ");
    MidOrderTraverse(root);
    printf("\n");

    printf("postordertraverse: ");
    PostOrderTraverse(root);
    printf("\n");

    printf("\ntest search node: \n");
    int search_value = 30;
    AVLNode* foundnode = SearchNode(root,search_value);
    if(foundnode != nullptr){
        printf("node %d find \n",search_value);
    }else{
        printf("node %d not find\n",search_value);
    }

    search_value = 100;
    foundnode = SearchNode(root,search_value);
    if(foundnode != nullptr){
        printf("node %d find \n",search_value);
    }else{
        printf("node %d not find\n",search_value);
    }

    printf("\ntest delete node: \n");
    root = DeleteNode(root,10);
    printf("delete node 10 midordertraverse: ");
    MidOrderTraverse(root);
    printf("\n");

    root = DeleteNode(root,30);
    printf("delete node 30 midordertraverse: ");
    MidOrderTraverse(root);
    printf("\n");

    root = DeleteNode(root,50);
    printf("delete node 50 midordertraverse: ");
    MidOrderTraverse(root);
    printf("\n");

    printf("\ntest destroy avl tree: \n");
    DestroyTree(root);
    root = nullptr;
    printf("avl tree has been destroyed");

}

int main(){

    TestAvlTree();

    return 0;
}
